<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title>阿拉伯数字转换大写</title>
<meta name="description" content="">
<meta name="keywords" content="">
<link href="" rel="stylesheet">
<script type="text/javascript">
/**
 * 把数字转换为大写
 */
function numberTransform() {
	var number = document.getElementById('number').value;
	var varTransform = document.getElementById('transform');
	var numPart;
	var digitPart;
	var number = number.toString();
	var digitPos = number.indexOf(".");
	var sequence = [];
	var isLastDigitZero = false;
	var posSoundMap = {
		1: null, 	// 个
		2: '拾', 	// 十
		3: '佰', 	// 百
		4: '千', 	// 千
		5: '万', 	// 万
		6: '拾', 	// 十万
		7: '佰', 	// 百万
		8: '千', 	// 千万
		9: '亿', 	// 亿
		10: '拾', 	// 十亿
		11: '佰', 	// 百亿
		12: '千', // 千亿
		13: '兆', // 兆
	};

	//数字位数超过十二位就不读
	if (number.length > 12) {
		return false;
	}

	// number: 123.45
	// numPart: 123
	// digitPart: 45
	if (digitPos == -1) {
		numPart = number;
		digitPart = '';
	} else {
		numPart = number.substr(0, digitPos);
		digitPart = number.substr(digitPos + 1, number.length);
		if (digitPart === '0') {
			digitPart = '';
		}
	}

	if (numPart === '0') {
		sequence.push('零');
		varTransform.value = sequence.join('');
		return;
	}

	var numPartLength = numPart.length;
	for (var i=0; i<numPartLength; i++) {
		var digit = numPart.substr(i,1);
		if (parseInt(digit) > 0) {
			isLastDigitZero = false;
			sequence.push(digit);
			if (posSoundMap[numPartLength - i]) {
				sequence.push(posSoundMap[numPartLength - i]);
			}
		} else {
			// 处理末尾的多个连续0
			if (parseInt(numPart.substr(i)) === 0) {
				break;
			}

			if (isLastDigitZero) {
				continue;
			} else {
				isLastDigitZero = true;
				if ((numPartLength - i) >= 5 && (numPartLength - i) < 10) {
					sequence.push('万');
				}
				if ((numPartLength - i) >= 10) {
					sequence.push('亿');
				}
				sequence.push(digit);
			}
		}
	}

	// digitPartSounds: [4,5]
	if (digitPart) {
		sequence.push('点');
		var digitPartLength = digitPart.length;
		for (var i=0; i<digitPartLength; i++) {
			var digit = digitPart.substr(i,1);
			sequence.push(digit);
		}
	}

	for (var i=0; i<sequence.length; i++) {
		switch(sequence[i]) {
			case '0':
				sequence[i] = '零';
				break;
			case '1':
				sequence[i] = '壹';
				break;
			case '2':
				sequence[i] = '贰';
				break;
			case '3':
				sequence[i] = '叁';
				break;
			case '4':
				sequence[i] = '肆';
				break;
			case '5':
				sequence[i] = '伍';
				break;
			case '6':
				sequence[i] = '陆';
				break;
			case '7':
				sequence[i] = '柒';
				break;
			case '8':
				sequence[i] = '捌';
				break;
			case '9':
				sequence[i] = '玖';
				break;
		}
	}

	varTransform.value = sequence.join('');
}

window.onload = function() {
	document.getElementById('button').addEventListener('click',function() {numberTransform();},false);
}
</script>
</head>
<body>
	<p><input type="text" name="number" id="number"></p>
	<p><input type="button" name="button" id="button" value="转换"></p>
	<p><input type="text" name="transform" id="transform" size="50"></p>
</body>
</html>